package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityTransportInvoiceInfoBinding;
import com.sgb.kjwl.di.transport.DaggerTransportComponent;
import com.sgb.kjwl.di.transport.TransportModule;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.model.entity.transport.TransportOrderEntity;
import com.sgb.kjwl.view.constant.RouterKey;
import com.sgb.kjwl.view.ui.adapter.TransportInvoiceInfoAdapter;
import com.sgb.kjwl.viewmodel.transport.TransportInvoiceInfoViewModel;
import com.swgk.core.base.di.AppComponent;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * @author: 杨畔
 * @date: 3/10/21 3:00 PM
 * @Description: 开票信息页面
 */
public class TransportInvoiceInfoActivity extends AppActivity {

    @Inject
    TransportInvoiceInfoViewModel mViewModel;
    private ActivityTransportInvoiceInfoBinding mBinding;
    //订单信息类
    private TransportOrderEntity mEntity;

    /**
     * 跳转凭证页面
     */
    public static void start(Context context, TransportOrderEntity entity) {
        Intent intent = new Intent(context, TransportInvoiceInfoActivity.class);
        intent.putExtra(RouterKey.DATA, entity);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerTransportComponent.builder()
                .appComponent(appComponent)
                .transportModule(new TransportModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void init() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_transport_invoice_info);
        mBinding.setLifecycleOwner(this);
        //获取数据
        mEntity = getIntent().getParcelableExtra(RouterKey.DATA);
        initRecycler();
        initEvent();
    }

    private void initRecycler() {
        //货源信息
        List<SingleItemEntity> list = new ArrayList<>();
        mViewModel.syncInfo(list, mEntity);
        TransportInvoiceInfoAdapter adapter = new TransportInvoiceInfoAdapter(list);
        mBinding.rvTransportInvoiceInfo.setNestedScrollingEnabled(false);
        mBinding.rvTransportInvoiceInfo.setLayoutManager(new LinearLayoutManager(this));
        adapter.bindToRecyclerView(mBinding.rvTransportInvoiceInfo);
    }

    private void initEvent() {
        mBinding.actionBar.setOnBackClickListener(view -> finish());
    }
}
